package negocio;

import beans.TablaTo;
import dao.TablaDAO;
import java.util.ArrayList;
import java.util.HashMap;
import utildb.Transaction;
import utildb.TransactionException;

public class TablaManager {

    	public TablaManager() {
		super();
	}	

	public void registrarTabla(TablaTo to) throws TablaManagerException {
		Transaction t = new Transaction();
		try {
			if(to.codigoVacio())
			    throw new TablaManagerException("Código esta en blanco");
			else {
				TablaDAO fact = new TablaDAO(t);
				fact.create(to);
				t.commit();
			}
		} catch (TransactionException e) {
			t.rollback();
			throw new TablaManagerException(e.getMessage());
		} finally {
			t.close();
		}
	}

	public void eliminarTabla( String codigo) throws TablaManagerException {
		Transaction t = new Transaction();
		try {
			TablaDAO dao = new TablaDAO(t);
			dao.eliminar(codigo);
			t.commit();
		} catch (TransactionException e) {
			t.rollback();
			throw new TablaManagerException(e.getMessage());
		} finally {
			t.close();
		}
	}

	public ArrayList getArrayTablas(String codigo) throws TablaManagerException {
		Transaction t = new Transaction();
		try {
			TablaDAO dao = new TablaDAO(t);
			ArrayList all = dao.arrayTablas(codigo);
			t.close();
			return all;
		} catch (TransactionException e) {
			throw new TablaManagerException(e.getMessage());
		} finally {
			t.close();
		}
	}
	public HashMap getHashMapTablas() throws TablaManagerException {
		Transaction t = new Transaction();
		try {
			TablaDAO dao = new TablaDAO(t);
			HashMap tablas = dao.hashMapTablas();
			t.close();
			return tablas;
		} catch (TransactionException e) {
			throw new TablaManagerException(e.getMessage());
		} finally {
			t.close();
		}
	}
}
